<?php
class NavigModel{
		
	/**
	 * zwraca liste sekcji danej strony
	 *
	 * @param Int_type $__id_page
	 * @return Arr
	 */
	private static function _get_data_menu_page($__grupa, $__parent=0){
		global $config;
		$__q_pages_for_grup = "SELECT a.id_page, a.id_p_page, redirect, to_url, id_lang, page_name, page_url, description FROM ".PAGES." a,".PLANG." b  
			WHERE b.id_page = a.id_page AND  a.id_grup = '{$__grupa}' AND a.plock != 1 
			".((is_null($__parent)) ? "" : " AND a.id_p_page = '{$__parent}'" )." 
			AND b.id_lang = ".tools::__mres($config->__lang)." ORDER BY a.lp_page";
			
		$__pages = tools::__adodb('getAll',$__q_pages_for_grup);
		return $__pages;
		
	}

	/**
	 * zwraca nazwe strony przez wartosc url
	 *
	 * @param unknown_type $__page_url
	 * @return unknown
	 */
	private static function __get_page_name_by($__page_url){
		global $config;
		$__xml = XMLReader::open("xml/pages_{$config->__lang}.xml");

		$__q_page_name = "SELECT page_name FROM ".PLANG."
		WHERE  page_url = ".tools::__mres($__page_url)." AND b.id_lang = ".tools::__mres($config->__lang);
			
		$__page_name = tools::__adodb('getOne',$__q_page_name);
		return $__page_name;
				
	}

	/**
	 * zwraca numer strony do wygenerowania
	 *
	 * @return Int
	 */
	public static function _get_page_menu($__grupa,$__parent = 0){
		$__pages = NavigModel::_get_data_menu_page($__grupa, $__parent);
		return $__pages;
	}
	
	/**
	 * zwraca nazwe strony
	 *
	 * @param unknown_type $__page_url
	 * @return unknown
	 */
	public static function _get_page_name($__page_url){
		return NavigModel::__get_page_name_by($__page_url);
	}
}
?>
